package com.flyee.viewer
{
	import com.flyee.service.pool.ObjectCollection;
	import com.flyee.utils.GCHleper;
	import com.flyee.utils.GenerateIDTool;
	import com.flyee.viewer.pack.helper.ItemHelper;
	import com.flyee.viewer.pack.helper.ItemViewModel;
	import com.flyee.viewer.pack.helper.PackageContainer;
	
	import flash.display.Bitmap;
	import flash.events.Event;
	
	import mx.events.CloseEvent;
	import mx.events.FlexEvent;

	public class PackagePanelViewer extends BaseWindowViewer 
	{
		public var vid:String=GenerateIDTool.generateID();
		
		[Embed(source="resource/equip1.png")]
		private var EquipIcon1:Class;
		[Embed(source="resource/equip2.png")]
		private var EquipIcon2:Class;
		[Embed(source="resource/redDrug.jpg")]
		private var RedDrug:Class;
		private var packBox:PackageContainer=null;

		public function PackagePanelViewer()
		{
			this.addEventListener(FlexEvent.CREATION_COMPLETE, initEvent);
			this.addEventListener(CloseEvent.CLOSE, closePanelEvent);
			this.showCloseButton=true;
		}

		private function initEvent(event:Event):void
		{
			packBox=new PackageContainer();
			this.addChild(packBox);
			this.width=packBox.sizeWH.x;
			this.height=packBox.sizeWH.y;
			this.canDragMove = true;
			initItems();
		}

		/**
		 * 初始化包裹中的道具
		 * @param data
		 *
		 */
		private function initItems():void
		{

			for(var i:int=0; i < 3; i++)
			{
				var temp:ItemViewModel=new ItemViewModel();

				temp.dataModel.packageId="f232112222";
				temp.dataModel.isSystem=false;
				temp.dataModel.position=i;
				temp.dataModel.tip="fdfdfdfddsd";
				var equip:Bitmap=null;
				if(i == 2){
					equip = new RedDrug();
					temp.data = ObjectCollection.skillPanelViewer.drugItems.getItemAt(0);
					temp.dataModel.position = i;
					temp.dataModel.isSystem = false;
					temp.dataModel.id = "reddrug";
					temp.icon=equip.bitmapData;
				}else
				if (i == 0)
				{
					equip=new EquipIcon1();
					temp.dataModel.name="白色套装";
					temp.dataModel.id="4028800f1a4c4944011a4e85e3a50010";
					temp.icon=equip.bitmapData;
					temp.dataModel.itemType = 2000;
				}
				else if(i == 1)
				{
					equip=new EquipIcon2();
					temp.icon=equip.bitmapData;
					temp.dataModel.name="紫色套装";
					temp.dataModel.itemType = 2000;
					temp.dataModel.id="4028800f1a4c4944011a4e85e3a50011";
				}
				packBox.addOneProp(temp);
			}
		}

		private function removePanelEvent(event:Event):void
		{
			//this.removeEventListener(Event.REMOVED_FROM_STAGE,removePanelEvent);
			dispose();
		}

		private function closePanelEvent(event:Event):void
		{
			if (ObjectCollection.uiContainer.contains(this))
			{
				ObjectCollection.uiContainer.removeChild(this);
			}
			dispose();
			ObjectCollection.packPanelViewer = null;
		}
		
		public function updateItem(item:ItemViewModel):void{
			var temp:ItemViewModel = ItemHelper.cloneProp(item.dataModel,false,item.icon);
			packBox.addOneProp(temp);
		}

		override public function dispose():void
		{
			packBox.clearAll();
			GCHleper.clearAll(this);
		}
	}
}



